/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦，本文采用木兰宽松许可证第2版]
 * 
 * https://zhiqim.org/project/zhiqim_kit/zhiqim_git.htm
 *
 * ZhiqimGit is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.git.objer.objectid;

import java.io.IOException;

import org.zhiqim.git.GitWalker;
import org.zhiqim.git.objer.model.Tree;


/**
 * 修改过程中的文件目录对象
 * 
 * @version v1.0.0 @author zhichenggang 2017-3-28 新建与整理
 */
public class RevTree extends RevObject
{
    private byte[] buffer;
    
    public RevTree(final ObjectId id)
    {
        super(id);
    }

    /***********************************************************************/
    //子类必须实现的5个方法
    /***********************************************************************/
    
    @Override
    public final int getType()
    {
        return OBJ_TREE;
    }
    
    @Override /** 解析头部信息 */
    public void parseHeaders(GitWalker walk) throws IOException
    {
        buffer = loadCanonical(walk);
        setParsed();
    }

    @Override /** 解析主体部分 */
    public void parseBody(GitWalker walk) throws IOException
    {
        if (!isParsed())
            parseHeaders(walk);
    }
    
    @Override
    public final byte[] getContent()
    {
        return buffer;
    }
    
    @Override
    public final void disposeContent()
    {
        buffer = null;
    }
    
    /***********************************************************************/
    //设置&获取属性
    /***********************************************************************/
    
    public Tree getTree()
    {
        return new Tree().parse(buffer);
    }
}
